package cn.yiueil.advice;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

@Slf4j
public class MyAdvice implements InvocationHandler {
    private final Object target;
    public MyAdvice(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("前置广告");
        log.info("前置广告");
        Object ret = null;
        try {
            ret = method.invoke(target, args);
        } catch (Exception e) {
            System.out.println("异常广告");
            log.info("异常广告");
            e.printStackTrace();
        }
        System.out.println("后置广告");
        log.info("后置广告");
        return ret;
    }
}
